/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgExchange
    {
        private readonly Dictionary<int, CfgExchange> _dataMap;
        private readonly List<CfgExchange> _dataList;


        public TbCfgExchange(ByteBuf _buf)
        {
            //first read common data
            _TbCommonExchange _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonExchange(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgExchange>(size * 3 / 2);
            _dataList = new List<CfgExchange>(size);

            for (int i = 0; i < size; i++)
            {
                CfgExchange _v;
                _v = CfgExchange.DeserializeCfgExchange(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgExchange> DataMap => _dataMap;
        public IReadOnlyList<CfgExchange> DataList => _dataList;

        public CfgExchange Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgExchange] config not found,id:" + key.ToString());

            return null;
        }

        public CfgExchange GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "exchange";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgExchange LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgExchange(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgExchange
    {
        private CfgExchange(ByteBuf _buf, _TbCommonExchange _commonData)
        {
            Id = _buf.ReadInt();
            Type = _buf.ReadInt();
            GetItem = _buf.ReadInt();
            Bulk = _buf.ReadBool();
            { int dataIndex = _buf.ReadInt() - 1; CostItems = _commonData._field0[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; GetItems = _commonData._field1[dataIndex]; }
            Limit = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; CritWeights = _commonData._field2[dataIndex]; }
            { int dataIndex = _buf.ReadInt() - 1; CritMultiples = _commonData._field3[dataIndex]; }
            Coefficient = _buf.ReadInt();
            ResetType = _buf.ReadInt();

            PostInit();
        }

        internal static CfgExchange DeserializeCfgExchange(ByteBuf _buf, _TbCommonExchange _commonData)
        {
            return new CfgExchange(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 类型(1:教会捐献 2：金币兑换 3：体力兑换 4：魂彩合成5：人偶碎片回收 6：空间宝藏)
        /// </summary>
        public int Type { get; private set; }
        /// <summary>
        /// 兑换获得道具
        /// </summary>
        public int GetItem { get; private set; }
        /// <summary>
        /// 是否允许批量兑换
        /// </summary>
        public bool Bulk { get; private set; }
        /// <summary>
        /// 消耗物品id|数量
        /// </summary>
        public IReadOnlyList<IReadOnlyList<int>> CostItems { get; private set; }
        /// <summary>
        /// 获得物品id|数量
        /// </summary>
        public IReadOnlyList<IReadOnlyList<int>> GetItems { get; private set; }
        /// <summary>
        /// 剩余次数
        /// </summary>
        public int Limit { get; private set; }
        /// <summary>
        /// 暴击权重
        /// </summary>
        public IReadOnlyList<int> CritWeights { get; private set; }
        /// <summary>
        /// 暴击倍数
        /// </summary>
        public IReadOnlyList<float> CritMultiples { get; private set; }
        /// <summary>
        /// 系数（0基础值，1玩家等级）
        /// </summary>
        public int Coefficient { get; private set; }
        /// <summary>
        /// 重置类型（0不重置，1 4点重置）
        /// </summary>
        public int ResetType { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonExchange
    {

        internal IReadOnlyList<IReadOnlyList<IReadOnlyList<int>>> _field0 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<IReadOnlyList<int>>> _field1 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<int>> _field2 { get; private set; }
        internal IReadOnlyList<IReadOnlyList<float>> _field3 { get; private set; }
        internal _TbCommonExchange(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][][]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[][] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1][]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int[] __v1; { int __n2 = _buf.ReadSize(); var __f2 = new int[__n2]; __v1 = __f2; for (var __i2 = 0 ; __i2 < __n2 ; __i2++ ){ int __v2; __v2 = _buf.ReadInt(); __f2[__i2] = __v2;} } __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][][]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[][] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1][]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int[] __v1; { int __n2 = _buf.ReadSize(); var __f2 = new int[__n2]; __v1 = __f2; for (var __i2 = 0 ; __i2 < __n2 ; __i2++ ){ int __v2; __v2 = _buf.ReadInt(); __f2[__i2] = __v2;} } __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new int[__n0][]; _field2 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ int[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new int[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ int __v1; __v1 = _buf.ReadInt(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new float[__n0][]; _field3 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ float[] __v0; { int __n1 = _buf.ReadSize(); var __f1 = new float[__n1]; __v0 = __f1; for (var __i1 = 0 ; __i1 < __n1 ; __i1++ ){ float __v1; __v1 = _buf.ReadFloat(); __f1[__i1] = __v1;} } __f0[__i0] = __v0;} }
        }

    }
}
